package com.hs.utils;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;

import static com.hs.constant.SystemConstant.NICKNAME_PREFIX;

/**
 * @author 何森
 * @since 2023-08-07-9:24
 */
public class RandomUserInfoUtil {

    private static final int[] indexArr = new int[]{3, 1, 4, 5, 9, 2, 6, 7, 8, 10};
    private RandomUserInfoUtil() {}

    public static String generateUserName(String phone) {
        char[] chars = StrUtil.reverse(phone).toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0, j = 1; i < 10; i += 2, j += 2) {
            char codePoint = (char) ((chars[indexArr[i]] - 48) * 10 + (chars[indexArr[j]] - 48) + 23);
            if ((codePoint > 47 && codePoint < 58)
             || (codePoint > 64 && codePoint < 91)
             || (codePoint > 96 && codePoint < 123)) {
                sb.append(codePoint);
                continue;
            }
            sb.append(chars[indexArr[i]]).append(chars[indexArr[j]]);
        }
        return sb.append(chars[0]).toString();
    }

    public static void main(String[] args) {
        System.out.println("generateUserName(\"18460363747\") = " + generateUserName("18460363747"));
    }

    public static String randomPassword() {
        return RandomUtil.randomString(6);
    }

    public static String randomNickname() {
        return NICKNAME_PREFIX + RandomUtil.randomString(6);
    }

}
